//
//  CoachsBookTextFieldCell.m
//  CoachsBook
//
//  Created by huiyong li on 2022/8/20.
//

#import "CoachsBookTextFieldCell.h"

@interface CoachsBookTextFieldCell ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *arrowImage;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation CoachsBookTextFieldCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier])
    {
        [self setViews];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)setViews
{

    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 10, 120, 30)];
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    self.titleLabel.textColor = rgba(51, 51, 51, 1);
    
    
    self.contentField = [[UITextField alloc]initWithFrame:CGRectMake(130, 10, APPwidth-145, 30)];
    self.contentField.font = [UIFont systemFontOfSize:14];
    self.contentField.textAlignment = NSTextAlignmentRight;
    self.contentField.textColor = rgba(51, 51, 51, 1);
    
    self.arrowImage = [[UIImageView alloc]initWithFrame:CGRectMake(APPwidth-30, 17, 16, 16)];
    self.arrowImage.image = [UIImage imageNamed:@"mine_arrow"];
    self.arrowImage.hidden = YES;
    
    self.lineView = [[UIView alloc]initWithFrame:CGRectMake(15, 49, APPwidth-30, 1)];
    self.lineView.backgroundColor = rgba(245, 245, 245, 1);
    

    
    
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.contentField];
    [self.contentView addSubview:self.arrowImage];
    [self.contentView addSubview:self.lineView];
}

-(void)cellFillWithModel:(CoachsBookInputModel *)model
{
    self.titleLabel.text = model.title;
    self.contentField.placeholder = model.prompt;
    self.contentField.text = model.content;
    
    if (model.showArrow) {
        self.arrowImage.hidden = NO;
        self.contentField.frame = CGRectMake(130, 10, APPwidth-160, 30);
    }
    else
    {
        self.arrowImage.hidden = YES;
        self.contentField.frame = CGRectMake(130, 10, APPwidth-145, 30);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
